package com.fastCms.business.frame.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fastCms.business.frame.constant.CommonConst;
import com.fastCms.business.frame.pojo.entity.CloudUserRoleRel;
import com.fastCms.business.frame.daos.CloudUserRoleRelMapper;
import com.fastCms.business.frame.service.CloudUserRoleRelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平台系统用户与角色关联表 服务实现类
 * </p>
 *
 * @author liusq
 * @since 2019-05-27
 */
@Service
public class CloudUserRoleRelServiceImpl extends ServiceImpl<CloudUserRoleRelMapper, CloudUserRoleRel> implements CloudUserRoleRelService {

    @Override
    public CloudUserRoleRel findByUserId(String userId) {
        QueryWrapper<CloudUserRoleRel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        queryWrapper.eq("user_id", userId);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<CloudUserRoleRel> findByRoleId(String roleId) {
        QueryWrapper<CloudUserRoleRel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        queryWrapper.eq("state", CommonConst.STATE.VALID);
        return this.list(queryWrapper);
    }

}
